package com.fengmi.cart.controller;

import com.fengmi.cart.Cart;
import com.fengmi.cart.service.ICartService;
import com.fengmi.comm.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("cart")
public class CartController {
    @Autowired
    ICartService iCartService;
    @RequestMapping("addCart")
    public ResultVO addCart(String skuId, Integer buyNum){
        return  iCartService.addCart(skuId,buyNum);
    }
    @RequestMapping("listCart")
    public ResultVO listCart() {
        return  iCartService.listCart();
    }
  //1 前端传字符串     后端   定义形参 ，对象
  //2 前端传对象{ }    后端   @RequestBody 对象
 // 3 前端传[{},{}]   后端   @RequestBody List<对象>


    //后端传给前端  ResultVO
    @RequestMapping("updateCart")
    public ResultVO updateCart(@RequestBody  List<Cart> carts) {
        return  iCartService.updateCart(carts);
    }

    @RequestMapping("updateCartNew")
    public ResultVO  updateCartNew( @RequestBody List<Cart> carts){
        return  iCartService.updateCartNew(carts);
    }
}
